package com.li.drug.utils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.HashMap;

/**
 * 给前端返回的json格式数据
 */
public class ResultMapUtil {

    /**
     * 登录返回结果
     * @return
     */
    public static HashMap<String ,Object> getHashMapLogin(String msg,String code){
        HashMap<String ,Object> resultMap = new HashMap<>();
        resultMap.put("msg",msg);
        resultMap.put("code",code);
        if("1".equals(code)){
            resultMap.put("icon",1);
        }else {
            resultMap.put("icon",2);
        }
        resultMap.put("anim",4);
        return resultMap;
    }

    /**
     * 分页查询结果
     * @param object
     * @return
     */
    public static HashMap<String ,Object> getHashMapMysqlPage(Page<?> object){
        HashMap<String ,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",object.getTotal());
        map.put("data",object.getRecords());
        return map;
    }

    /**
     * 异常数据统一处理
     * @param e
     * @return
     */
    public static HashMap<String ,Object> getHashMapException(Exception e){
        HashMap<String ,Object> map = new HashMap<>();
        map.put("code","0");
        map.put("msg",e.getMessage());
        return map;
    }

    /**
     * 保存成功统一返回格式
     */
    public static HashMap<String ,Object> getHashMapSave(int i){
        HashMap<String ,Object> resultMap = new HashMap<>();
        if(i==0){
            resultMap.put("msg","保存失败");
            resultMap.put("code",1);
            resultMap.put("icon",5);
            resultMap.put("anim",6);
        }else {
            resultMap.put("msg","保存成功");
            resultMap.put("code",0);
            resultMap.put("icon",1);
            resultMap.put("anim",4);
        }
        return resultMap;
    }

    /**
     * 更新成功统一返回格式
     */
    public static HashMap<String ,Object> getHashMapUpdate(int i){
        HashMap<String ,Object> resultMap = new HashMap<>();
        if(i==0){
            resultMap.put("msg","更新失败");
            resultMap.put("code",1);
            resultMap.put("icon",5);
            resultMap.put("anim",6);
        }else {
            resultMap.put("msg","更新成功");
            resultMap.put("code",0);
            resultMap.put("icon",1);
            resultMap.put("anim",4);
        }
        return resultMap;
    }

    /**
     * 删除成功统一返回格式
     */
    public static HashMap<String ,Object> getHashMapDel(int i){
        HashMap<String ,Object> resultMap = new HashMap<>();
        if(i==0){
            resultMap.put("msg","删除失败");
            resultMap.put("code",1);
            resultMap.put("icon",5);
            resultMap.put("anim",6);
        }else {
            resultMap.put("msg","删除成功");
            resultMap.put("code",0);
            resultMap.put("icon",1);
            resultMap.put("anim",4);
        }
        return resultMap;
    }
}
